home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / turbovis / tvtool17.zip / ACTLIB.ZIP / TOOLS.ZIP / VOLLABEL.C < prev   
C/C++ Source or Header  |  1993-09-07  |  3KB  |  122 lines

  1. /*  Copyright (C) 1993   Marc Stern  (internet: stern@mble.philips.be)  */
  2.  
  3. #include "tools.h"
  4. #include <direct.h>
  5. #include <string.h>
  6. #include <stdlib.h>
  7.  
  8.  
  9. #ifndef FA_LABEL
  10. #define FA_LABEL  0x08
  11. #endif
  12.  
  13. static int near vol_kill( int drive, char *vol )
  14. {
  15.  union REGS regs;
  16.  struct SREGS sregs;
  17.  struct xfcb buf;
  18.  char cdir[_MAX_PATH], dir[] = "x:\\\0           ";
  19.  void far *ptr;
  20.  
  21.  if ( getcurdir(drive + 1, cdir) ) return -1;
  22.  *dir = drive + 'A';
  23.  if ( chdir(dir) ) 
  24.     {
  25.      chdir( cdir ); 
  26.      return -1; 
  27.     }
  28.  
  29.  strncpy( &dir[2], vol, strlen(vol) );
  30.  
  31.  /* Parse the filename into an FCB */
  32.  regs.h.ah = 0x29;
  33.  regs.h.al = 0;
  34.  sregs.ds  = FP_SEG( dir );
  35.  regs.x.si = FP_OFF( dir );
  36.  ptr = &buf.xfcb_fcb;
  37.  sregs.es  = FP_SEG( ptr );
  38.  regs.x.di = FP_OFF( ptr );
  39.  intdosx( ®s, ®s, &sregs );
  40.  
  41.  if ( ! regs.h.al )
  42.     {
  43.       /* Volume labels require extended FCB's */
  44.       buf.xfcb_flag = 0xff;
  45.       buf.xfcb_attr = FA_LABEL;
  46.  
  47.       /* Delete the old label */
  48.       regs.h.ah = 0x13;
  49.       ptr = &buf;
  50.       sregs.ds  = FP_SEG( ptr );
  51.       regs.x.dx = FP_OFF( ptr );
  52.       intdosx( ®s, ®s, &sregs );
  53.     }
  54.  
  55.  chdir( cdir );
  56.  
  57.  return regs.h.al;
  58. }
  59.  
  60.  
  61.  
  62. /***
  63.  *
  64.  *  Function   :    vollabel
  65.  *
  66.  *  Topics     :    Get/Set disk volume label
  67.  *
  68.  *  Parameters :    in       int drive         0 = A:, 1 = B:
  69.  *                  in/out   char *vol         volume label
  70.  *
  71.  *  Decisions  :    - If *vol = '\0', it is filled with disk volume label.
  72.  *                  - Otherwise, vol is copied onto disk volume label.
  73.  *
  74.  *  Return code:    0 if OK
  75.  *                 -1 if error
  76.  ***/
  77.  
  78. int vollabel( int drive, char *vol )
  79. {
  80.  int result, fd;
  81.  struct find_t finfo;
  82.  char buf[20];
  83.  
  84.  *buf = drive + 'A';    
  85.  strcpy( buf + 1, ":\\*.*" );
  86.  
  87.  result = _dos_findfirst( buf, FA_LABEL, &finfo );
  88.  
  89.  if ( ! *vol )       /* only get the volume label */
  90.     {
  91.      if ( ! result )
  92.         {
  93.          /* suppress '.' */
  94.          int dotpos = strchr(finfo.name, '.') - finfo.name;
  95.          strncpy( vol, finfo.name, dotpos );
  96.          strcpy( vol + dotpos, finfo.name + dotpos + 1 );
  97.         }
  98.      return 0;
  99.     }
  100.  
  101.  /* Delete volume label */
  102.  if ( ! result )
  103.     if ( vol_kill(drive, finfo.name) ) return -1;
  104.  
  105.  /* Construct absolute filename */
  106.  strncpy( &buf[3], vol, 11 );
  107.  
  108.  /* Insert a '.' between 8th and 9th character */
  109.  buf[15] = '\0';
  110.  buf[14] = buf[13];
  111.  buf[13] = buf[12];
  112.  buf[12] = buf[11];
  113.  buf[11] = '.';
  114.  
  115.  /* Create new volume label */
  116.  fd = _creat( buf, FA_LABEL );
  117.  if ( fd < 0 ) return -1;
  118.  close( fd );
  119.  
  120.  return 0;
  121. }
  122.